#ifndef CARDMANAGER_H
#define CARDMANAGER_H

#include "BasicCard.h"
#include "TLVPacketer.h"
#include "Defines.h"

class CCardManager
{
public:
	CBasicCard BasicCard;
	CCardSet CardStack;


public:
	CCardManager() 
	{
		CardStack = BasicCard.Pics;
		CardStack.Wash();
	}
	void PlayerAlloc(CPlayer player[], int playernum, int cardnum, TLVpacketer *back)
	{
		CCardSet item;
		if (playernum * cardnum > CardStack.size()) return;
		for (int i = 0; i < playernum; i++)
		{
			item = CardStack.PopFrontTo(cardnum);
			for (int n = 0; n < cardnum; n++)
			{
				player[i].PicInHand.push_front(*item[n]);
			}
			AddCard2Data( item, back[i][P_GAME_GETCARD] );
		}
		//ItemsUsed.splice(ItemsUsed.begin(), item);
	}
	void AddCard2Data(CCardSet &item, DataFlow &data)
	{
		int cardnum = item.size();
		if (cardnum <= 0) return;
		char *c = new char[cardnum];
		for (int n = 0; n < cardnum; n++)
		{
			c[n] = (*item[n])->Index;
		}
		data = DataFlow(c, cardnum);
		delete [] c;
	}
	void AddCard2Data(CPicture *pic, DataFlow &data)
	{
		int cardnum = data.GetLength() + 1;
		if (cardnum <= 0) return;
		char *c = new char[cardnum];
		data.CopyData( c, data.GetLength() );
		c[cardnum - 1] = pic->Index;

		data = DataFlow(c, cardnum);
		delete [] c;
	}
};




























#endif